package view.builder;

import java.awt.BorderLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

import view.DBInfoUiBuilderTest;
import view.MainFrame;

public class MainUiBuilder implements UIBuilder, ItemListener  {

	MainFrame mainFrame;
	JMenuBar menuBar;
	JMenu dbMenu;
	JMenuItem dbStatusMenuItem;
	
	@Override
	public void uiBuild(MainFrame mainFrame) {
		this.mainFrame = mainFrame;
		JPanel panel = new JPanel();
		
		menuBar = new JMenuBar();
		menuBar.setName("menuBar");
		
		dbMenu = new JMenu("dbInfo");
		dbMenu.setName("dbMenu");
		
		dbStatusMenuItem = new JMenuItem("dbStatus");
		dbStatusMenuItem.setName("dbStatus");
		dbMenu.add(dbStatusMenuItem);
		
		menuBar.add(dbMenu);
		
		panel.add(new JLabel("MainUiBuilder"), BorderLayout.SOUTH);
		
		this.mainFrame.setJMenuBar(menuBar);
		this.mainFrame.setContentPane(panel);
		
		setEvent();
	}
	
	//메뉴 선택 이벤트 
	public void setEvent(){
		dbStatusMenuItem.addItemListener(this);
	}

	@Override
	public void itemStateChanged(ItemEvent event) {
		if(event.getStateChange() == ItemEvent.SELECTED){
			mainFrame.setUIBuilder(new DbInfoUIBuilder());
			mainFrame.uiBuild();
		}
	}
}